//
//  MBCircelProgressView.m
//  MobellCloud_ios
//
//  Created by cherry pu on 2018/1/22.
//  Copyright © 2018年 zhangXin. All rights reserved.
//

#import "MBCircelProgressView.h"

@implementation MBCircelProgressView

- (instancetype)initWithFrame:(CGRect)frame
{
    if(self = [super initWithFrame:frame]){
        self.backgroundColor = [UIColor clearColor];
    }
    return self;
}

- (void)setProgress:(CGFloat)progress
{
    _progress = progress;
    
    [self setNeedsDisplay];
}

- (void)drawRect:(CGRect)rect
{
    CGPoint center = CGPointMake(rect.size.width * 0.5, rect.size.height * 0.5);
    CGFloat startAngle = - M_PI_2;
    CGFloat endAngle = self.progress * M_PI * 2 - M_PI_2;
    
    [[UIColor colorWithWhite:1.0 alpha:0.1] setStroke];
    
    UIBezierPath * backCirclePath = [UIBezierPath bezierPathWithArcCenter:center radius:rect.size.width * 0.5 - 2 startAngle:0 endAngle:M_PI * 2 clockwise:YES];
    [backCirclePath setLineCapStyle:kCGLineCapRound];
    [backCirclePath setLineJoinStyle:kCGLineJoinRound];
    [backCirclePath setLineWidth:4];
    [backCirclePath stroke];
    
    [[UIColor colorWithWhite:1.0 alpha:0.8] setStroke];
    
    UIBezierPath * circlePath = [UIBezierPath bezierPathWithArcCenter:center radius:rect.size.width * 0.5 - 2 startAngle:startAngle endAngle:endAngle clockwise:YES];
    [circlePath setLineCapStyle:kCGLineCapRound];
    [circlePath setLineJoinStyle:kCGLineJoinRound];
    [circlePath setLineWidth:4];
    [circlePath stroke];
}

@end
